import Vue from 'vue';
import Cookie from 'js-cookie';
import Router from 'vue-router';

Vue.use(Router);

const router = new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      name: 'manage',
      component: () =>
        import(/* webpackChunkName: "manage" */ './views/Manage.vue'),
      beforeEnter: (to, from, next) => {
        if (!Cookie.get('token')) {
          router.push('/login');
        }
        next();
      }
    },
    {
      path: '/login',
      name: 'login',
      component: () =>
        import(/* webpackChunkName: "login" */ './views/Login.vue')
    },
    {
      path: '/reset-password',
      component: () =>
        import(/* webpackChunkName: "reset-password" */ './views/ResetPassword.vue'),
      children: [
        {
          path: '',
          component: () =>
            import(/* webpackChunkName: "reset-password" */ './components/account/PhoneCode.vue')
        }
      ]
    }
  ]
});

export default router;
